<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>bbs.jsp</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
	$(function() {
		$.get("sort/getSort", function(res) {
			var sel = $("#sel");
			var option = "<option value='0'>全部</option>";
			var sortId="${SORTID}"
			sel.append(option);
			$(res).each(
					function() {
						if(this.id==sortId){
							var option = "<option value='"+this.id+"' selected>" + this.name
							+ "</option>";
							sel.append(option);
						}else{
							var option = "<option value='"+this.id+"'>" + this.name
							+ "</option>";
							sel.append(option);
						}
					});
		}, 'json');
	});

	$(function() {
		$("#btn").click(function() {
			location = "Detail/toShopping";
		});
	});
</script>
</head>
<body>
	<div class="box" align="center">
		<form method="get" action="Detail/getDetails">
			<span>请选择商品分类</span> <select name="sortId" id="sel">
			</select>
			<input type="submit" value="搜索"/>
		</form>
		
		<br />
		<table align="center" border="1"  cellpadding="0"
			cellspacing="0" style="text-align: center; width: 60%">
			<tr class="firstTr">
				<th width="10%">商品编号</th>
				<th width="10%">商品名称</th>
				<th width="10%">商品分类</th>
				<th width="25%">产地</th>
				<th width="15%">生产日期</th>
				<th width="10%">单价(元)</th>
				<th width="10%">剩余数量</th>
				<th width="10%">购买</th>
			</tr>
			<c:forEach items="${PAGE.list}" var="detail" varStatus="num">
				<tr>
					<td>${detail.id }</td>
					<td>${detail.name }</td>
					<td>${detail.sort.name}</td>
					<td>${detail.address}</td>
					<td><fmt:formatDate  value="${detail.creatDate}" pattern="yyyy-MM-dd"/></td>
					<td>${detail.price }</td>
					<td>${detail.remaining }</td>
					<td><a href="Detail/toShopping?id=${detail.id}&sortId=${detail.sortId}">购买</a></td>
				</tr>
			</c:forEach>
		</table>
		<div align="center" class="pagesDiv">
			<a href="Detail/getDetails?pageNum=1" class="firstPage">首页</a> <a
				href="Detail/getDetails?pageNum=${PAGE.pageNum-1}&sortId=${detail.sortId}">上一页</a> <a
				href="Detail/getDetails?pageNum=${PAGE.pageNum+1}&sortId=${detail.sortId}">下一页</a> <a
				href="Detail/getDetails?pageNum=${PAGE.totalPage}&sortId=${detail.sortId}">末页</a> <span>第</span>
			${PAGE.pageNum} <span>页/共</span> ${PAGE.totalPage} <span>页</span>
		</div>
	</div>
</body>
</html>